package com.stm.bi.model;

import com.stm.framework.annotation.ResParam;
import com.stm.framework.model.CustomizePage;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: chenyingjun
 * @Date: 2025/02/10
 */
public class DatatablePage<E> {

    @ResParam(label = "标题")
    private List<Title> titles = new ArrayList<>();
    @ResParam(label = "数据集")
    private List<RowData> datas;

    @ResParam(label = "总记录数")
    private long total;
    @ResParam(label = "页面大小")
    private long size = 20;
    @ResParam(label = "当前页码")
    private long current = 1;

    @ResParam(label = "扩展数据")
    private E extend;

    public static DatatablePage of(CustomizePage<Map> customizePage){
        DatatablePage datatablePage = new DatatablePage();
        List<RowData> records = new ArrayList<>();
        for (Map map : customizePage.getRecords()) {
            RowData rowData = new RowData();
            rowData.putAll(map);
            records.add(rowData);
        }
        datatablePage.setDatas(records);
        datatablePage.setTotal(customizePage.getTotal());
        datatablePage.setCurrent(customizePage.getCurrent());
        datatablePage.setSize(customizePage.getSize());
        return datatablePage;
    }

    public static DatatablePage of(CustomizePage<Map> customizePage, List<Title> titles){
        DatatablePage datatablePage = DatatablePage.of(customizePage);
        datatablePage.setTitles(titles);
        return datatablePage;
    }


    public List<Title> getTitles() {
        return titles;
    }

    public E getExtend() {
        return extend;
    }

    public DatatablePage<E> setExtend(E extend) {
        this.extend = extend;
        return this;
    }

    public DatatablePage setTitles(List<Title> titles) {
        this.titles = titles;
        return this;
    }



    public long getTotal() {
        return total;
    }

    public DatatablePage<E> setTotal(long total) {
        this.total = total;
        return this;
    }

    public long getSize() {
        return size;
    }

    public DatatablePage<E> setSize(long size) {
        this.size = size;
        return this;
    }

    public long getCurrent() {
        return current;
    }

    public DatatablePage<E> setCurrent(long current) {
        this.current = current;
        return this;
    }

    public List<RowData> getDatas() {
        return datas;
    }

    public DatatablePage<E> setDatas(List<RowData> datas) {
        this.datas = datas;
        return this;
    }
}
